#pragma once

#include "IXFileWriter.h"

#include "XFileDef.h"
#include "XBaseObjImpl.h"


class CXFileWriterImpl : public CXBaseObjImpl<IXFileWriter>
{
    typedef CXBaseObjImpl<IXFileWriter> superclass;
    DEF_SKIN_CLASS_SINGLE_INTF(CXFileWriterImpl,
        superclass,
        gs_strGuidXSkin,
        IXFileWriter,
        0);
public:
    CXFileWriterImpl();
    virtual ~CXFileWriterImpl();

public:
    // IXFileWriter
    virtual HRESULT STDMETHODCALLTYPE   WriteFolder(IN LPCTSTR szRootPath, IN LPCTSTR szXFilePath);

    virtual HRESULT STDMETHODCALLTYPE   CreateXFile(IN LPCTSTR szXFilePath);
    virtual HRESULT STDMETHODCALLTYPE   AppendLocalFile(IN LPCTSTR szXFilePath, IN LPCTSTR szRelativePath, IN LPCTSTR szRootPath);

protected:
    HANDLE  XCreateXFile(LPCTSTR szXFilePath, BOOL bAppend);
    BOOL    XAppendLocalFile(HANDLE hXFile, LPCTSTR szRelativeFilePath, LPCTSTR szRootPath);
    void    XCloseXFile(HANDLE hXFile);
    HRESULT XWriterFolder(HANDLE hXFile, LPCTSTR szRelativeFolderPath, LPCTSTR szRootPath);

    stXFileIndex* GetXFileIndex(LPCTSTR szRelativePath, HANDLE hLocalFile);
    void    ReleaseXFileIndex(stXFileIndex* pIndex);
};


